package com.itxx.keyCase.demo3.domain;

import java.text.Collator;
import java.util.Comparator;
import java.util.Locale;

public class Student implements Comparator<Student> {

        private  String name;
        private  String gender;
        private  Integer age;


    @Override
    public int compare(Student o1, Student o2) {
        int result = o1.getAge()-o2.getAge();
        if (result==0){
            Collator instance = Collator.getInstance(Locale.CHINA);
           result= instance.compare(o1.getName(), o2.getName());
        }
        if (result==0){
            Collator instance = Collator.getInstance(Locale.CHINA);
            result= instance.compare(o1.getGender(), o2.getGender());
        }
        return result;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (name != null ? !name.equals(student.name) : student.name != null) return false;
        if (gender != null ? !gender.equals(student.gender) : student.gender != null) return false;
        return age != null ? age.equals(student.age) : student.age == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (gender != null ? gender.hashCode() : 0);
        result = 31 * result + (age != null ? age.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", gender='" + gender + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Student(String name, String gender, Integer age) {
        this.name = name;
        this.gender = gender;
        this.age = age;
    }

    public Student() {
    }
}
